// pages/mes/my-customers/my-customers.js
const app = getApp();
import Toast from '../../../component/toast/toast';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        customers: []
    },
    selectItem(e) {
        let index = e.currentTarget.dataset.index;
        let id = this.data.customers[index].ServiceId;
        wx.navigateTo({
            url: '/pages/mes/my-customers-detail/my-customers-detail?serviceId=' + id,
        })
    },
    getMyCustomers() {
        let that = this;
        wx.showLoading({
            title: '加载中...',
            mask: true
        })
        wx.request({
            url: app.globalData.serverAddress.getMyCustomers,
            data: {
                userId: app.userInfo.Id
            },
            header: {
                'Authorization': "Bearer " + app.globalData.token
            },
            method: 'GET',
            success: function(res) {
                console.log(res);
                if (res.statusCode == 200 && res.data.CodeStatus == 20000) {
                    that.setData({
                        customers: res.data.BodyContent
                    });
                }
                Toast(res.data.Message);
            },
            fail: function(res) {
                console.log("fail getMyCustomers：" + JSON.stringify(res));
            },
            complete: function(res) {
                wx.hideLoading();
            },
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.getMyCustomers();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})